<?php
/**
 * Created by JetBrains PhpStorm.
 * User: xiaobai
 * Date: 13-5-23
 * Time: 下午5:29
 * To change this template use File | Settings | File Templates.
 */

function authentication($obj, $attr = array()) {
    if( count($attr) > 0 && isset($attr['token']) && !empty($attr['token']) ) {
        $obj->load->model('universal/system_token_model');
        $tokens = $obj->system_token_model->get_system_token();
        if(is_array($tokens) && array_key_exists('error', $tokens)) {
            return $tokens;
        } else {
            if(in_array($attr['token'], $tokens)) {
                return TRUE;
            } else {
                $error = $obj->error_code_library->getError('system', 'params', 'auth_failed');
                log_message('error', json_encode($error), FALSE, $obj->_log_dir);
                return $error;
            }
        }

    } else {
        $error = $obj->error_code_library->getError('system', 'params', 'no_auth_parameter');
        log_message('error', json_encode($error), FALSE, $obj->_log_dir);
        return $error;
    }
}

function parameter_validate($obj, $attr = array()) {
    if( array_key_exists('word',$attr) === TRUE && !empty($attr['word']) && !empty($attr['platform'])) {
        log_message('notes', 'ACCESS BY '. json_encode($attr), FALSE, $obj->_log_dir);
        return TRUE;
    } else {
        $error = $obj->error_code_library->getError('system', 'params', 'no_must_parameter');
        log_message('error', json_encode($error), FALSE,$obj->_log_dir);
        return $error;
    }
}

function url_validate($obj, $attr = array()) {
    if(array_key_exists('url',$attr) === TRUE && !empty($attr['url'])) {
        return TRUE;
    } else {
        $error = $obj->error_code_library->getError('system', 'params', 'no_must_parameter');
        log_message('error', json_encode($error), FALSE,$obj->_log_dir);
        return $error;
    }
}